package com.sp.api.springbootapi.service;

import com.sp.api.springbootapi.dao.GoodsDao;
import com.sp.api.springbootapi.model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by weidewang on 2018/7/2
 */
@Service
public class GoodsService {
    @Resource
    private GoodsDao goodsDao;

    public void getGoodsById(){
        int goodsId = 1;
        //根据相同的id查询出商品信息，赋给2个对象
        Goods goods1 = goodsDao.getGoodsById(goodsId);
        Goods goods2 = goodsDao.getGoodsById(goodsId);

        //打印当前商品信息
        System.out.println(goods1);
        System.out.println(goods2);

        //更新商品信息1
        goods1.setStatus(2);//修改status为2
        int updateResult1 = goodsDao.updateGoodsUseCAS(goods1);
        System.out.println("修改商品信息1"+(updateResult1==1?"成功":"失败"));

        //更新商品信息2
        goods2.setStatus(2);//修改status为2
        int updateResult2 = goodsDao.updateGoodsUseCAS(goods1);
        System.out.println("修改商品信息2"+(updateResult2==1?"成功":"失败"));

    }
}
